package gameObject;


import java.awt.event.KeyEvent;

import main.Core;
import main.Input;
import action.BlendAction;
import action.PeriodicAction;
import content.Content;
import data.ImageSprite;

/**
 * 
 * @author Ygor
 * 
 */
public class Arrow extends ImageSprite {

	private PeriodicAction periodicMov;
	private BlendAction blend;
	private int amountToMove; // o tanto que a arrow meche quando se move.
	private int position; // position can be 0 (startGame), 1 (load) and 2 (exit);
	private int numPosition;
	private float speed;
	private float initialPositionX;
	private float initialPositionY;
	private boolean vertical = true;

	public Arrow(int x, int y, int w, int h, Core c, int numPosition) {
		super(Content.loadImage("MENU_Arrow"), x, y, w, h, c);
		blend = new BlendAction();
		periodicMov = new PeriodicAction();
		periodicMov.start(6.6f, (float)x, 1f);

		speed = 0.2f;
		position = 0;
		initialPositionX = x;
		initialPositionY = y;
		this.numPosition = numPosition - 1;
	}

	@Override
	public void Update(float elapsedTime) {
		setX((int)(float)periodicMov.link((float)initialPositionX, (float)elapsedTime));
		
		if (blend.isRunning()) {
			if (vertical) {
				this.setY((int)(float)blend.link((float)initialPositionY, elapsedTime));
			} else {
				this.setX((int)(float)blend.link((float)initialPositionX, elapsedTime));
				periodicMov.start(6.6f, (float)this.getX(), 1f, false);
			}
		}
		
	}

	public void OnKeyPress(KeyEvent keyPressed) {
		if(vertical){
			if (Input.down(keyPressed)) {
				if (position < numPosition) {					
					initialPositionY = this.getY();
					blend.start((float)(this.getY() + amountToMove), (float)this.getY(), speed);
					position++;
				}
			} else if (Input.up(keyPressed)) {
				if (position > 0) {					
					initialPositionY = this.getY();
					blend.start((float)(this.getY() - amountToMove), (float)this.getY(), speed);
					position--;
				}
			}
		}else{
			if (Input.right(keyPressed)) {
				if (position < numPosition)
				{
					initialPositionX = this.getX();
					blend.start((float)(this.getX() + amountToMove), (float)this.getX(), speed);
					position++;
				}
			}else if (Input.left(keyPressed)) {
				if (position > 0)
				{
					initialPositionX = this.getX();
					blend.start((float)(this.getX() - amountToMove), (float)this.getX(), speed);
					position--;
				}
			}
		}
	}

	/**
	 * @return the position
	 */
	public int getPosition() {
		return position;
	}

	/**
	 * @param position
	 *            the position to set
	 */
	public void setPosition(int position) {
		this.position = position;
	}

	/**
	 * @return the numPosition
	 */
	public int getNumPosition() {
		return numPosition;
	}

	/**
	 * @param numPosition
	 *            the numPosition to set
	 */
	public void setNumPosition(int numPosition) {
		this.numPosition = numPosition;
	}

	/**
	 * @return the amountToMove
	 */
	public int getAmountToMove() {
		return amountToMove;
	}

	/**
	 * @param amountToMove
	 *            the amountToMove to set
	 */
	public void setAmountToMove(int amountToMove) {
		this.amountToMove = amountToMove;
	}

	/**
	 * @return the vertical
	 */
	public boolean isVertical() {
		return vertical;
	}

	/**
	 * @param vertical
	 *            the vertical to set
	 */
	public void setVertical(boolean vertical) {
		this.vertical = vertical;
	}

	/**
	 * @return the speed
	 */
	public float getSpeed() {
		return speed;
	}

	/**
	 * @param speed the speed to set
	 */
	public void setSpeed(float speed) {
		this.speed = speed;
	}

}
